<template>
  <div class="">数据历史</div>
</template>

<script>
import ToolsBtn from "../../components/Tools/ToolsBtn";
import TableList from "../../components/Table/TableList";
import TableProp from "../../utils/tableProps.js";
import Pagination from "../../components/Pagination/pagination";
import PageProp from "../../utils/pageProps.js";
import THead from "./HLogs.js"
export default {
  name: "Logs",
  data() {
    return {
      table: TableProp,
      page: PageProp,
      toolsData: {
        title: "用户管理",
        oBtnShow: [
          { btn0: false }, // 新增按钮
          { btn1: true }, // 刷新按钮
          { btn2: false }, // 搜索按钮
          { btn3: false }, // 设置按钮
          { btn4: false } // 导出Excel按钮
        ]
      },
      editDialog: {
        title: "编 辑",
        visible: false,
        submitVisible: false,
        data: null
      },
      showPrise: false,
      showRentPrise: false,
      imgUrl: '',
      timeData: ''
    };
  },
  components: {
    ToolsBtn,
    TableList,
    Pagination
  },
  created(){
    this.table.tHead = THead;
    this.table.hasOperation = false;
    this.table.identifier = true;
    this.table.operation.data = [
      {
        id: 1,
        label: "编 辑",
        Fun: "handleEdit",
        btnType: "text",
        plain: false,
        size: "mini",
        className: "handleEdit"
      }
    ];
    this.getList(1,50);
  },
  methods: {
    // 新增数据
    addData(){
      console.log("新增数据")
      this.handleEdit();
    },
    // 刷新数据
    refresh(){
      console.log("刷新数据")
    },
    // 搜索数据
    search(){
      console.log("搜索数据")
    },
    // 设置字段
    fieldSet(){
      console.log("设置字段")
    },
    // 隐藏表格操作列
    hasOperation(){
      console.log("隐藏表格操作列");
      this.table.hasOperation = !this.table.hasOperation;
    },
    getList(pageNo, pageSize) {
      this.table.data = [];
      this.table.loading = true;
      const params = {
        pageNo,
        pageSize
      };
      // console.log(params)
      this.$api.RECORD.getData(params)
        .then(res => {
          console.log(res);
          const data = res.data;
          const total = res.count;
          this.table.data = data;
          this.page.total = total;
          this.table.loading = false;
        })
        .catch(err => {
          console.log(err);
        });
    },
    // 分页大小
    pageSizeChange(size) {
      // console.log(`每页 ${size} 条`);
      const tableDataLength = this.table.data.length;
      this.page.pageSize = size;
      if (tableDataLength < this.page.pageSize) {
        this.getList(1, size);
      } else {
        const pageNo = this.page.currentPage;
        this.getList(pageNo, size);
      }
    },
    // 翻页
    pageCurrentChange(pageNo) {
      // console.log(`当前页: ${pageNo}`);
      this.page.currentPage = pageNo;
      const size = this.page.pageSize;
      this.getList(pageNo, size);
    },
    // 编辑模态框
    handleEdit(index, row){
      console.log(row)
      this.editDialog.visible = true
      if(index !== undefined && row !== undefined){
        console.log(1)
        this.showPrise = true;
        this.showRentPrise = false;
        const title = `${row.id_IMEI}编辑`;
        this.editDialog.title = title;
        const data = row;
        this.editDialog.data = data;
      } else {
        this.showRentPrise = true;
        this.showPrise = false;
        this.editDialog.title = "添加";
        this.editDialog.data = {};
      }
    },
    // 删除
    handleDel(){

    },
    closeDialog(name){
      if(name === "editDialog"){
        this[name].submitVisible = false;
        this[name].data = null;
      }
      this[name].visible = false;
    },
    // 图片上传成功
    fileSuccess(res){
      console.log(res)
       this.imgUrl = res.url
       console.log(this.imgUrl)
    }
  }
};
</script>

<style lang="scss" scoped>
</style>
